/*
******************************************************************************************
**
**  Copyright (C) 2011, Fujian WITSI Micro-electronic Tech. CO.,LTD., All Rights Reserved.
**
******************************************************************************************
*/
/*
******************************************************************************************
**
**	File: apitrans.h
**
**	Brief:
**
**	Logs:
**		2012.12.26		Created by ttlc
**
******************************************************************************************
*/
#ifndef ___APITRANS_H___
#define ___APITRANS_H___

/*
******************************************************************************************
**	include files 
******************************************************************************************
*/
#include <string.h>

#ifdef __cplusplus
extern "C"{
#endif
/*
******************************************************************************************
**	global referenced macro defines & type defines
******************************************************************************************
*/
 
enum {
    OPEN_API = 0,
    CLOSE_API,
    READ_API,
    WRITE_API,
    SELECT_API,
    LSEEK_API,
    TRUNCATE_API,
    UNLINK_API,
    IOCTL_API,

    GETTIMEOFDAY_API,
    SETTIMEOFDAY_API,
    TIMEOUT_START_API,
    TIMEOUT_TEST_API,

    
    LCD_SET_ATTRI_API,
    LCD_CLRSCR_API,
    LCD_DISP_IMG_API,
    LCD_DISP_STRING_API,
    LCD_DISP_HLINE_API,
    LCD_DISP_VLINE_API,
    LCD_GOTO_XY_API,
    LCD_SET_FONT_COLOR_API,

    KB_GET_KEY_API,
    KB_GET_STR_API,

    KB_GET_AMOUNT_API,
        
    SERIAL_INIT_API,
    SERIAL_WRITE_API,
    SERIAL_READ_API,
    SERIAL_CLRBUF_API,

    SHA1_STARTS_API,
    SHA1_UPDATE_API,
    SHA1_FINISH_API,
    SHA2_STARTS_API,
    SHA2_UPDATE_API,
    SHA2_FINISH_API,
    DESKEY_API,
    DES_API,
    DES3KEY2_API,
    DES3KEY3_API,
    DES3_API,

    RSAPUBLICFUNC_API,
    RNG_GET_BYTE_API,
    RNG_GET_STRING_API,
    CRC16_API,
    CRC16_ITU_T_API,
    ASC2BCD_API,
    BCD2ASC_API,

    SEC_KEY_INJECTION_API,
    SEC_CRL_INJECTION_API,
    SEC_GET_KEYGRP_NO_API,
    SEC_SET_CURR_KEYGRP_API,
    SEC_PIN_WORKEY_API,
    SEC_SET_WORKKEY_API,
    SEC_MAC_X919_API,
    SEC_TRACK_ENCRYPT_API,
    SEC_MAC_9690_API,

    SEC_MAC_DC_ECB_API,
    SEC_UNSET_KEY_API,
    SEC_SET_MASTERKEY_API,
    SEC_UPDATE_MASTERKEY_API,
    SEC_SM2_VERIFY_SIGNATURE_API,
    SEC_SM3_CALC_API,
    SEC_MAC_X99_API,
    SEC_PIN_ENCRYPT_API,

    SYS_LOAD_LIBRARY_API,
    SYS_RUN_APP_API,
    SYS_UPDATE_MOD_API,

    ICC_STATUS_API,
    ICC_POWER_UP_API,
    ICC_SEND_APDU_API,
    ICC_POWER_DOWN_API,

    POS_ENTRY_API,
    RESET_API,
    MDELAY_API,
    BUZZER_START_API,
    BUZZER_STOP_API,
    LED_CTRL_API,
    SECURITY_STATUS_API,
    NV_WRITE_API,
    NV_READ_API,
    SYS_GET_PARAM_API,
    SYS_SET_PARAM_API,
    

    
    SEC_MAC_9606_API,

    SYS_SLEEP_API,
    LCD_GET_TYPE_API,
    LCD_SET_FONT_API,
    LCD_SET_SPACE_API,
    LCD_GET_SIZE_API,

    MALLOC_API,
    REALLOC_API,
    FREE_API,

    PRN_START_API,
    PRN_PUTCH_API,
    PRN_STRING_API,
    PRN_SET_FONT_API,
    PRN_SET_UNDERLINE_API,
    PRN_SET_SPACING_API,
    PRN_SET_GREY_API,
    PRN_GET_STATUS_API,
    PRN_IMAGE_API,
    PRN_INIT_API,

    MODEM_GET_SQ_API,
    MODEM_GET_INFO_API,
    MODEM_GET_STATION_INFO_API,
    TCP_OPEN_API,
    TCP_CLOSE_API,
    TCP_CONNECT_API,
    TCP_WRITE_API,
    TCP_READ_API,

};

/*
** RETURN:
**	>0: package length, package in the cmd buffer
**	=0: ok and nothing to respone
**	<0: error code while excusive cmd
typedef int fn_cmd_api_t(unsigned char *cmd, int len);
*/
typedef void *(*sys_apitrans_t)(int cmd);

typedef struct {
    unsigned cmd; 
    void *pfunc;
}apitrans_t;

//typedef void (*apitrans_t)(void);
#define __apitrans_entry	__attribute__((__used__, section(".apitrans")))

#define APITRANS_API_CALL(CMD, FN) \
        static const apitrans_t _apitrans_initcall_##CMD\
        __attribute__((__used__, section(".apitrans")))= {\
        .cmd = CMD,\
        .pfunc = FN,\
        }

#if 0
        
#define apitrans_initcall(fn)    \
        static const apitrans_t _apitrans_initcall_##fn \
        __attribute__((__used__, section(".apitrans"))) = fn

#endif

/*
******************************************************************************************
**	global referenced variables
******************************************************************************************
*/

/*
******************************************************************************************
**	global function prototype
******************************************************************************************
*/
/*
**	RETURN:
**		if success return cmd_num, return -1 for regiester failed!
*/

/*
**========================================================================================
**	End of this file.
**	Don't insert any data after this block.
**========================================================================================
*/
#ifdef __cplusplus
}
#endif

#endif	//___APITRANS_H___

